package com.sdwl.brcl.validation.validation;


import com.sdwl.brcl.validation.enums.EnumAware;
import org.apache.commons.lang3.StringUtils;

/**
 * @author xied
 * @date 2021年06月11日 14:14
 */
public class EnumAwareValidator implements Validator {
    private EnumAware[] enumAwares;
    private int type;
    public static final int IN = 1;
    public static final int NOT_IN = 2;

    public EnumAwareValidator(EnumAware[] enumAwares, int type) {
        this.enumAwares = enumAwares;
        this.type = type;
    }

    @Override
    public boolean validate(Object value) {
        boolean result;
        EnumAware[] var3;
        int var4;
        int var5;
        EnumAware enumAware;
        if (this.type == 1) {
            result = false;
            var3 = this.enumAwares;
            var4 = var3.length;

            for (var5 = 0; var5 < var4; ++var5) {
                enumAware = var3[var5];
                if (StringUtils.equals(enumAware.getCode(), (String) value)) {
                    result = true;
                    break;
                }
            }

            return result;
        } else if (this.type != 2) {
            return false;
        } else {
            result = true;
            var3 = this.enumAwares;
            var4 = var3.length;

            for (var5 = 0; var5 < var4; ++var5) {
                enumAware = var3[var5];
                if (StringUtils.equals(enumAware.getCode(), (String) value)) {
                    result = false;
                    break;
                }
            }

            return result;
        }
    }

    @Override
    public String validateCode() {
        if (this.type == 1) {
            return "in";
        } else {
            return this.type == 2 ? "not_in" : "";
        }
    }

    @Override
    public String validateMsg(Object value, String validateName) {
        if (this.type == 1) {
            return validateName + "不在合规范围";
        } else {
            return this.type == 2 ? validateName + "在不合规范围" : "";
        }
    }
}
